/* ************************************************************************** */^M
/* Example of a syndication feed reader using the Project Rome API with */^M
/* BSF4ooRexx */^M
/* current version of Rome: rome1.0.jar https://rome.dev.java.net/ */^M
/* You need to implement this API plus the JDOM API */^M
/* jdom.jar , you can find this at https://jdom.org/ */^M
/* */^M
/* This is a simple example of how to create a syndication feed with ooRexx */^M
/* With a GUI extension and the possibility to aggregate files too */ ^M
/* created by Martin Stoppacher date: 26.12.2009 (c) 2009 */^M
/* license:ÊÊÊÊLGPL 3.0ÊÊÊÊÊÊÊused versions: Java 1.6, ooRexx 4.0, Bsf4ooRexx */^M
/* (Lesser Gnu Public License version 3.0), */^M
/* cf. <http://www.gnu.org/licenses/lgpl.html> */^M
/* ************************************************************************** */^M
^M
say "hello this creates a syndfeeds"^M
tmpColl = .array ~new^M
insert = .urlinsert~new^M
i=0^M
^M
/* grafical extensin */^M
frame2=.bsf~new("java.awt.Frame", "Please enter the FeedType")^M
/* ss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, */^M
/* rss_1.0 rss_2.0 or atom_0.3 */^M
^M
frame2~bsf.addEventListener( 'window', 'windowClosing', 'call BSF "exit"')^M
frame2~setLayout(.bsf~new("java.awt.GridLayout",4,1))^M
type=.bsf~new("java.awt.TextField", "rss_2.0", 50)^M
but2=.bsf~new('java.awt.Button', 'Create Feed with Type')^M
but2~bsf.addEventListener('action', '', 'call create, type') ^M
tf=.bsf~new("java.awt.TextField", "http://rss.orf.at/fm4.xml", 50)^M
but=.bsf~new('java.awt.Button', 'insert url')^M
but~bsf.addEventListener('action', '', 'i=i+1')^M
but~bsf.addEventListener('action', '', 'insert~insert(tmpColl, tf~getText, i)')^M
frame2~add(type)
frame2~add(but2)
frame2~add(tf)
frame2~add(but)^M
frame2~~pack~~show~~toFront^M
do forever^M
INTERPRET .bsf~bsf.pollEventText^M
if result="SHUTDOWN, REXX !" then leave^M
end^M
^M
create: ^M
typet = type~getText^M
fileName = "test6_new_feed" typet /* set file name */^M
^M
/* converting the rexx date() to an other format */^M
datum = date()^M
parse var datum day mounth year^M
if mounth="Dec" then mounth=12^M
if mounth="Jan" then mounth=01 /* simply add the necessary once */^M
datum_new = year"-"mounth"-"day^M
say "Todays date: " datum_new^M
^M
call Syssleep 1^M
^M
say 'Your crated feed starts hear :'^M
^M
feed=.bsf~new("com.sun.syndication.feed.synd.SyndFeedImpl")^M
/* using syndfeedImpl to creat a feed using the independent object model */^M
feed~setFeedType(typet)^M
/* sets the type of this feed */^M
^M
desc = "My favorite webpages; format:_" typet^M
^M
feed~setTitle("This is a simple Sample")^M
feed~setDescription(desc)^M
feed~setAuthor("Martin Stoppacher")^M
feed~setLink("http://martinstoppacher.com")^M
feed~setLanguage("English")^M
^M
im=.bsf~new("com.sun.syndication.feed.synd.SyndImageImpl")^M
im~setTitle("A new image") ^M
im~setLink("http://www.freefoto.com/images/14/26/14_26_4---Trevi-Fountain--Rome--Italy_web.jpg")^M
im~setDescription("Trevi Fountain Rome")^M
im~setUrl("http://www.freefoto.com/images/14/26/14_26_4---Trevi-Fountain--Rome--Italy_web.jpg") ^M
^M
feed~setImage(im)^M
^M
auth =.bsf~new("java.util.ArrayList")^M
pers=.bsf~new("com.sun.syndication.feed.synd.SyndPersonImpl")^M
pers~setName("Martin Stoppacher") ^M
pers~setUri("martinstoppacher.com") ^M
pers~setEmail("office@artinstoppacher.com") ^M
auth~add(pers)^M
^M
pers2=.bsf~new("com.sun.syndication.feed.synd.SyndPersonImpl")^M
pers2~setName("A second person") ^M
pers2~setUri("the Uri of the person") ^M
pers2~setEmail("the persons email") ^M
auth~add(pers2)^M
^M
feed~setAuthors(auth)^M
--say feed~toString /* string representation of the feed */^M
^M
/* create a java SimpleDateFormat instance for entry~setPublishedDate */^M
DATE_PARSER = .bsf~new("java.text.SimpleDateFormat", "yyyy-MM-dd")^M
^M
/* creates a Java array list for the entries of the feed*/^M
entries =.bsf~new("java.util.ArrayList")^M
entry =.bsf~new("com.sun.syndication.feed.synd.SyndEntryImpl")^M
^M
/* add some entries to an entriy object */^M
entry~setTitle("The Project Rome Web Page")^M
entry~setPublishedDate(DATE_PARSER~parse(datum_new))^M
entry~setLink("https://rome.dev.java.net/")^M
entry~setUri("https://rome.dev.java.net/")^M
entry~setAuthor("dev.java.net")^M
^M
/* create a independent description content implemetation */^M
description=.bsf~new("com.sun.syndication.feed.synd.SyndContentImpl")^M
description~setType("text/plain")^M
description~setValue("ROME Web Page")^M
entry~setDescription(description)^M
/* add the description object to the entry object */^M
^M
/* create a new category; by adding the SyndCategoryImpl to a Java array */^M
/* object and this array object to the entry object */^M
cat =.bsf~new("java.util.ArrayList")^M
category=.bsf~new("com.sun.syndication.feed.synd.SyndCategoryImpl")^M
category~setName("Java") ^M
category~ setTaxonomyUri("https://rome.dev.java.net/") ^M
cat~add(category)^M
entry~setCategories(cat)^M
^M
/* add the entry to the Java entries array object */^M
entries~add(entry)^M
^M
/* a secound entry */^M
entry =.bsf~new("com.sun.syndication.feed.synd.SyndEntryImpl")^M
^M
entry~setTitle("Java 1.4 Documentation")^M
entry~setPublishedDate(DATE_PARSER~parse(datum_new))^M
entry~setLink("http://java.sun.com/j2se/1.4.2/docs/api/")^M
entry~setUri("http://java.sun.com/")^M
entry~setAuthor("java.sun.com/")^M
^M
description=.bsf~new("com.sun.syndication.feed.synd.SyndContentImpl")^M
description~setType("text/plain")^M
description~setValue("Documentation of the Java 1.4 API")^M
entry~setDescription(description)^M
^M
cat =.bsf~new("java.util.ArrayList")^M
category=.bsf~new("com.sun.syndication.feed.synd.SyndCategoryImpl")^M
category~setName("Documentation") ^M
category~ setTaxonomyUri("http://java.sun.com/j2se/1.4.2/docs/api/") ^M
cat~add(category)^M
entry~setCategories(cat)^M
^M
entries~add(entry)^M
^M
feed~setEntries(entries)^M
/* sets the Java array as entries of the feed */^M
^M
-- -------------^M
^M
/* this part adds the possibilitie of adding some aggregated antries to the */^M
/* feed. Take a look at example "rome8_a and b" */^M
^M
do y=i to 1 by -1^M
feedUrl=.bsf~new("java.net.URL",tmpColl~at(y))^M
input=.bsf~new("com.sun.syndication.io.SyndFeedInput")^M
xmlr=.bsf~new("com.sun.syndication.io.XmlReader", feedUrl)^M
infeed=input~build(xmlr)^M
entries~addAll(infeed~getEntries()) ^M
end^M
^M
-- ---------------^M
^M
/* writer part */ ^M
writer=.bsf~new("java.io.FileWriter",fileName)^M
output=.bsf~new("com.sun.syndication.io.SyndFeedOutput") ^M
output~output(feed,writer)^M
writer~close()^M
^M
say output~outputString(feed,1) -- usage of pretty print(0 yes or 1 no)^M
^M
PP : RETURN "[" || ARG(1)|| "]"^M
::requires BSF.cls^M
^M
::class urlinsert^M
^M
::method insert^M
use arg tmpColl, url, i^M
tmpColl[i] = url^M
^M
say "your urls are :"^M
SAY tmpColl~string || ":"^M
DO item OVER tmpColl^M
SAY "[" || item || "]"^M
END